package com.jy.framework.base.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    public static final String SUCCESSFUL_CODE = "1";
    public static final String SUCCESSFUL_MSG = "处理成功";

    private String code;
    private String msg;

    private T data;

    public static <T> Result<T> success(T data) {
        return new Result<T>(SUCCESSFUL_CODE, SUCCESSFUL_MSG, data);
    }

    public Result(String _code, String _msg) {
        this.code = _code;
        this.msg = _msg;
    }

    public static Result fail() {
        return new Result("-1", "系统异常");
    }

    public static Result fail(String msg) {
        return new Result("-1", msg);
    }

    public static Result fail(String _code, String _msg) {
        return Result.fail(_code, _msg, null);
    }

    public static Result fail(String _code, String _msg, Object data) {
        return new Result<>(_code, _msg, data);
    }

}
